package com.pilipili.zeus.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pilipili.commonutils.Result;
import com.pilipili.zeus.eduService.entity.EduCourse;
import com.pilipili.zeus.eduService.entity.EduTeacher;
import com.pilipili.zeus.eduService.entity.chapter.Chapter;
import com.pilipili.zeus.eduService.entity.vo.CourseFront;
import com.pilipili.zeus.eduService.entity.vo.CourseQuery;
import com.pilipili.zeus.eduService.entity.vo.SortCourse;
import com.pilipili.zeus.eduService.service.EduChapterService;
import com.pilipili.zeus.eduService.service.EduCourseService;
import com.pilipili.zeus.eduService.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduService/front")
public class TeacherController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduChapterService chapterService;
    @ApiOperation(value = "分页查询获取所有列表")
    @PostMapping("getFrontList/{current}/{limit}")
    public Result getFrontList(@PathVariable long current,
                               @PathVariable long limit){
        Page<EduTeacher> page=new Page<>(current,limit);
        Map<String,Object> map =teacherService.getFrontTeacherList(page);
        return  Result.ok().data(map);
    }
    @ApiOperation(value = "id获取作者详情")
    @GetMapping("getTeacherInfo/{teacherId}")
    public Result getTeacherInfo(@PathVariable String teacherId){
        EduTeacher teacher = teacherService.getById(teacherId);
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(queryWrapper);
        return  Result.ok().data("teacher",teacher).data("courseList",courseList);
    }
    @ApiOperation(value = "分页+条件查询获取番剧列表")
    @PostMapping("getCourseList/{current}/{limit}")
    public Result getCourseList(@PathVariable long current,
                                @PathVariable long limit,
                                @RequestBody(required = false) CourseQuery courseQuery){
        Page<EduCourse> page=new Page<>(current,limit);
        Map<String,Object> map =courseService.getCourseList(page,courseQuery);
        return  Result.ok().data(map);
    }
    @ApiOperation(value = "根据分类查询番剧信息")
    @PostMapping("getSortCourseInfo/{current}/{limit}/{sorId}")
    public Result getSortCourseInfo(@PathVariable long current,
                                    @PathVariable long limit,
                                    @PathVariable String sorId){
        IPage<SortCourse> page=new Page<>(current,limit);
        Map<String,Object> map = courseService.getSortCourseInfo(page,sorId);

        return Result.ok().data(map);
    }
    @ApiOperation(value = "id查询获取番剧小节列表和详细详细")
    @GetMapping("getCourseInfo/{courseId}")
    public Result getCourseInfo(@PathVariable String courseId){
        CourseFront courseInfo = courseService.getChapterVideoById(courseId);
        List<Chapter> list = chapterService.getChapterVideoById(courseId);
        return  Result.ok().data("courseInfo",courseInfo).data("list",list);
    }
}
